package com.mate.cloud.arthas.controller;


import com.mate.cloud.arthas.service.impl.Arthas;
import com.mate.cloud.common.response.BaseResponse;
import com.mate.cloud.common.web.controller.AdminBaseController;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * Spring Boot项目中集成Arthas
 *
 * @author: MI
 * @email: 448341911@qq.com
 * @createDate: 2023/10/29 18:19
 * @updateUser: MI
 * @updateDate: 2023/10/29 18:19
 * @updateRemark: 修改内容
 * @version: v1.0
 */
@Slf4j
@RestController
@RequestMapping("/arthas")
public class ArthasController extends AdminBaseController {


    @Resource
    private Arthas arthas;

    @GetMapping("/load")
    public BaseResponse load() {
        // 模拟 CPU 过高，这里注释掉了，测试时可以打开
        arthas.cpu();


        return successBodyResponse("Hell world!");
    }

    /**
     * 模拟线程阻塞
     * @return
     */
    @GetMapping("/thread")
    public BaseResponse thread() {

        // 模拟线程阻塞
        arthas.thread();

        return successBodyResponse("Hell world!");
    }

    /**
     * 模拟线程死锁
     *
     * @return
     */
    @GetMapping("/deadThread")
    public BaseResponse deadThread() {
        // 模拟线程死锁
        arthas.deadThread();

        return successBodyResponse("Hell world!");
    }

    /**
     * 模拟不断的向 hashSet 集合增加数据
     *
     * @return
     */
    @GetMapping("/hashSet")
    public BaseResponse addHashSetThread() {
        // 不断的向 hashSet 集合增加数据
        arthas.addHashSetThread();
        return successBodyResponse("Hell world!");
    }
}
